﻿using Common;
using Common.Dtos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Sigma.Admin.API.Authoriza;
using Sigma.Admin.API.Services;

namespace Sigma.Admin.API.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class UserController : ControllerBase
    {
        private readonly IUserService service;

        public UserController(IUserService service)
        {
            this.service = service;
        }
       
        [HttpGet]
        [PermissionAuthorize("User_GetAll")]
        public async Task<ApiResponse<List<UsersDto>>> GetAllUser()
        {
            return await service.GetAllAsync();
        }
        [HttpPost]
        [PermissionAuthorize("User_Add")]
        public async Task<ApiResponse> AddUser([FromBody] UsersDto usersDto)
        {
            return await service.AddAsync(usersDto);
        }

        [HttpPost]
        [PermissionAuthorize("User_Delete")]
        public async Task<ApiResponse> DeleteUser(List<UsersDto> id)
        {
            return await service.DeleteAsync(id);
        }

        [HttpPost]
        [PermissionAuthorize("User_Update")]
        public async Task<ApiResponse> UpdateUser([FromBody] List<UsersDto> usersDto)
        {
            return await service.UpdateAsync(usersDto);
        }

        [HttpPost]
        [PermissionAuthorize("User_EditPKey")]
        public async Task<ApiResponse> EditPKey([FromBody] UsersDto usersDto)
        {
            return await service.EditKeysAsync(usersDto);
        }
    }
}
